package io.renren.modules.student.service.impl;

import io.renren.common.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.student.dao.StudentDao;
import io.renren.modules.student.entity.StudentEntity;
import io.renren.modules.student.service.StudentService;


@Service("studentService")
public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {

    @Autowired
    StudentDao studentDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<StudentEntity> page = this.selectPage(
                new Query<StudentEntity>(params).getPage(),
                new EntityWrapper<StudentEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getStudentList(Map<String, Object> params) {
        PageUtils page=new PageUtils();
        int total=studentDao.getStudentTotal(params);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(studentDao.getStudentList(params));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

}
